/*     */ package btsm.bean;
/*     */ 
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.sql.ResultSet;
/*     */ import java.text.SimpleDateFormat;
/*     */ import org.apache.poi.hssf.usermodel.HSSFCell;
/*     */ import org.apache.poi.hssf.usermodel.HSSFCellStyle;
/*     */ import org.apache.poi.hssf.usermodel.HSSFDateUtil;
/*     */ import org.apache.poi.hssf.usermodel.HSSFRow;
/*     */ import org.apache.poi.hssf.usermodel.HSSFSheet;
/*     */ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/*     */ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/*     */ 
/*     */ public class excelio
/*     */ {
/*     */   public Boolean ReadRowCell(String rexcelpath, int rrowno, int rcol, String rviewname)
/*     */   {
/*  21 */     Boolean flag = Boolean.valueOf(true);
/*  22 */     FileInputStream fileIn = null;
/*  23 */     int rowtotal = 0;
/*  24 */     int rownum = 0;
/*  25 */     int cellnum = 0;
/*  26 */     String ssssql = "";
/*     */     try
/*     */     {
/*  29 */       fileIn = new FileInputStream(rexcelpath);
/*     */     } catch (Exception ex) {
/*  31 */       ex.printStackTrace();
/*     */ 
/*  33 */       flag = Boolean.valueOf(false);
/*     */     }
/*     */ 
/*     */     try
/*     */     {
/*  40 */       POIFSFileSystem fs = new POIFSFileSystem(fileIn);
/*  41 */       HSSFWorkbook wb = new HSSFWorkbook(fs);
/*     */ 
/*  43 */       HSSFSheet sheet = wb.getSheetAt(0);
/*     */ 
/*  45 */       rowtotal = sheet.getPhysicalNumberOfRows();
/*  46 */       rownum = rowtotal - rrowno;
/*  47 */       HSSFRow row = sheet.getRow(rrowno);
/*  48 */       cellnum = rcol;
/*     */ 
/*  50 */       String[] readrow = new String[cellnum];
/*     */ 
/*  52 */       int celltype = 0;
/*     */ 
/*  55 */       for (int i = 0; i < rownum; i++) {
/*  56 */         int k = 0;
/*  57 */         int kcellnum = 0;
/*  58 */         row = sheet.getRow(i + rrowno);
/*  59 */         for (int j = 0; j < cellnum; j++) {
/*  60 */           HSSFCell cell = row.getCell(j);
/*  61 */           celltype = cell.getCellType();
/*     */ 
/*  63 */           switch (celltype) {
/*     */           case 0:
/*  65 */             if (HSSFDateUtil.isCellDateFormatted(cell)) {
/*  66 */               SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/*  67 */               readrow[j] = sdf.format(cell.getDateCellValue());
/*     */             } else {
/*  69 */               readrow[j] = String.valueOf(cell.getNumericCellValue());
/*     */ 
/*  71 */               if ((readrow[j].indexOf(".") != -1) && (readrow[j].indexOf("E10") != -1)) {
/*  72 */                 readrow[j] = readrow[j].replaceAll(".", "");
/*  73 */                 readrow[j] = readrow[j].replaceAll("E10", "");
/*     */               }
/*     */               else
/*     */               {
/*  78 */                 int strpos = readrow[j].lastIndexOf(".");
/*  79 */                 int strend = readrow[j].length();
/*  80 */                 String intstr = readrow[j].substring(strpos + 1, strend);
/*  81 */                 if (Integer.parseInt(intstr) == 0)
/*  82 */                   readrow[j] = String.valueOf((int)cell.getNumericCellValue());
/*     */                 else {
/*  84 */                   readrow[j] = String.valueOf(cell.getNumericCellValue());
/*     */                 }
/*     */               }
/*     */             }
/*     */ 
/*  89 */             break;
/*     */           case 1:
/*  91 */             readrow[j] = cell.getStringCellValue();
/*  92 */             break;
/*     */           case 2:
/*  94 */             readrow[j] = String.valueOf(cell.getNumericCellValue());
/*  95 */             break;
/*     */           case 3:
/*  98 */             readrow[j] = "";
/*  99 */             break;
/*     */           default:
/* 101 */             readrow[j] = "";
/*     */           }
/*     */ 
/* 105 */           if (k < cellnum - 1) {
/* 106 */             if ((readrow[k].equalsIgnoreCase("")) || (readrow[k].equals("null")))
/* 107 */               ssssql = ssssql + "\"\",";
/*     */             else {
/* 109 */               ssssql = ssssql + '"' + readrow[k] + '"' + ",";
/*     */             }
/* 111 */             k++;
/*     */           }
/*     */ 
/*     */         }
/*     */ 
/* 118 */         if ((readrow[(cellnum - 1)].equalsIgnoreCase("")) || (readrow[(cellnum - 1)].equals("null")))
/* 119 */           ssssql = ssssql + "\"\"";
/*     */         else {
/* 121 */           ssssql = ssssql + '"' + readrow[(cellnum - 1)] + '"';
/*     */         }
/*     */ 
/* 125 */         String ssql = "insert into " + rviewname + " values(" + ssssql + ");";
/*     */ 
/* 127 */         for (int jk = 0; jk < cellnum; jk++)
/*     */         {
/* 129 */           if (readrow[jk].equalsIgnoreCase("")) {
/* 130 */             kcellnum++;
/*     */           }
/*     */         }
/* 133 */         if (kcellnum != cellnum)
/*     */         {
/* 135 */           dbConnector dbcon = new dbConnector();
/* 136 */           dbcon.execUpdate(ssql);
/* 137 */           dbcon.closeAll();
/*     */         }
/*     */ 
/* 140 */         ssssql = "";
/* 141 */         kcellnum = 0;
/*     */       }
/*     */ 
/* 145 */       if (fileIn != null) {
/* 146 */         fileIn.close();
/*     */       }
/*     */ 
/*     */     }
/*     */     catch (Exception ex)
/*     */     {
/* 152 */       ex.printStackTrace();
/* 153 */       System.out.println("读取Excel文件异常错误！");
/* 154 */       flag = Boolean.valueOf(false);
/*     */     }
/*     */ 
/* 157 */     return flag;
/*     */   }
/*     */ 
/*     */   public Boolean WriteRowCell(String sexcelpath, String wexcelpath, int wrowno, int wcol, ResultSet rs)
/*     */   {
/* 164 */     boolean flag = true;
/*     */ 
/* 166 */     int coltotal = wcol;
/*     */ 
/* 168 */     int colno = 0;
/*     */ 
/* 170 */     int colnum = coltotal - colno;
/* 171 */     String[] writerow = new String[colnum];
/*     */ 
/* 175 */     FileInputStream fileIn = null;
/* 176 */     FileOutputStream fileOut = null;
/*     */     try {
/* 178 */       fileIn = new FileInputStream(sexcelpath);
/*     */     } catch (Exception ex) {
/* 180 */       ex.printStackTrace();
/* 181 */       System.out.println("写Excel文件异常错误！");
/* 182 */       flag = false;
/*     */     }
/*     */ 
/*     */     try
/*     */     {
/* 187 */       POIFSFileSystem fs = new POIFSFileSystem(fileIn);
/*     */ 
/* 189 */       HSSFWorkbook wb = new HSSFWorkbook(fs);
/* 190 */       HSSFSheet sheet = wb.getSheetAt(0);
/*     */ 
/* 195 */       HSSFCellStyle cellStyle = wb.createCellStyle();
/* 196 */       HSSFRow row = sheet.getRow(wrowno - 1);
/* 197 */       HSSFCell cell = row.getCell((short)0);
/* 198 */       cellStyle = cell.getCellStyle();
/*     */ 
/* 200 */       int i = 0;
/*     */ 
/* 203 */       while (rs.next()) {
/* 204 */         row = sheet.getRow(i + wrowno);
/* 205 */         if (row == null)
/* 206 */           row = sheet.createRow(i + wrowno);
/*     */         int k;
/*     */         try
/*     */         {
/* 210 */           for (int j = colno; j < colnum; j++) {
/* 211 */             String strTmp = rs.getString(j + 1);
/* 212 */             if ((strTmp == null) || (strTmp.equalsIgnoreCase("null")))
/* 213 */               writerow[j] = "";
/*     */             else
/* 215 */               writerow[j] = strTmp;
/*     */           }
/*     */         } catch (Exception ex) {
/* 218 */           ex.printStackTrace();
/* 219 */           System.out.println("写Excel文件异常错误！");
/* 220 */           flag = false;
/*     */         }
/*     */         finally
/*     */         {
///*     */           int k;
/* 222 */           for (int kl = colno; kl < colnum; kl++)
/*     */           {
/* 225 */             cell = row.getCell((short)kl);
/* 226 */             if (cell == null) {
/* 227 */               cell = row.createCell((short)kl);
/*     */             }
/* 229 */             cell.setCellType(1);
/*     */ 
/* 232 */             cell.setCellStyle(cellStyle);
/*     */ 
/* 235 */             cell.setCellValue(writerow[kl]);
/*     */ 
/* 237 */             writerow[kl] = "";
/*     */           }
/* 239 */           i++;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 244 */       fileOut = new FileOutputStream(wexcelpath);
/*     */ 
/* 247 */       wb.write(fileOut);
/*     */ 
/* 249 */       if (fileOut != null) {
/* 250 */         fileOut.close();
/*     */       }
/* 252 */       if (fileIn != null)
/* 253 */         fileIn.close();
/*     */     }
/*     */     catch (Exception ex)
/*     */     {
/* 257 */       ex.printStackTrace();
/* 258 */       System.out.println("写Excel文件异常错误！");
/* 259 */       flag = false;
/*     */     }
/* 261 */     return Boolean.valueOf(flag);
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     btsm.bean.excelio
 * JD-Core Version:    0.6.2
 */